package com.qm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qm.mapper.UserMapper;
import com.qm.pojo.User;
import com.qm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 @author james
 @create 2021-04-22 9:53
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    private static Map<Integer,String> paramMap; //如果项目中固定写死的可以通过static方式维护
    static {
        Map<Integer,String> map = new HashMap<>();
        map.put(1, "username");
        map.put(2, "phone");
        map.put(3, "email");
        paramMap = map;
    }

    @Override
    public boolean checkUser(String param, Integer type) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        String column = paramMap.get(type);
        queryWrapper.eq(column,param);
        int count = userMapper.selectCount(queryWrapper);
        return count>0?true:false;
    }
}
